﻿<UserControl x:Class="System.Reactive.Contrib.Monitoring.UI.FolderPickerControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:System.Reactive.Contrib.Monitoring.UI"
             mc:Ignorable="d" 
             x:Name="pickerControl"
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <local:DriveIconConverter x:Key="DriveIconConverter"/>
        <ContextMenu x:Key="TreeItemContextMenu">
            <MenuItem Header="Create" Click="CreateMenuItem_Click"/>
            <MenuItem Header="Rename" Click="RenameMenuItem_Click"/>
            <MenuItem Header="Delete" Click="DeleteMenuItem_Click"/>
        </ContextMenu>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TreeView x:Name="TreeView" 
                  ItemsSource="{Binding ElementName=pickerControl,Path=Root.Childs}"
                  ItemContainerStyle="{Binding ElementName=pickerControl,Path=ItemContainerStyle}"
                  TreeViewItem.Expanded="TreeView_Expanded" TreeViewItem.Selected="TreeView_Selected" Background="#FFBDBDBD">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource ="{Binding Childs}">
                    <StackPanel Orientation="Horizontal" ContextMenu="{StaticResource TreeItemContextMenu}">
                        <Image Height="16" Width="16" Source="{Binding Converter={StaticResource DriveIconConverter}}"/>
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>
                    </StackPanel>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    </Grid>
</UserControl>
